# coding=utf-8
import arcpy

path = r'D:\WorkData\20250712四川河流\0813处理'
arcpy.env.workspace = path
arcpy.env.overwriteOutput = True
spatial_ref = arcpy.SpatialReference(4326)
riv = r'D:\WorkData\20250712四川河流\0813处理\rivs1.shp'.decode('utf-8')

for i in range(1,15):
    expression1 = "level = '{}'".format(i)
    cs1 = arcpy.da.SearchCursor(riv,['name','rivId'],where_clause=expression1)
    lv1RivList = []
    for row1 in cs1:
        lv1RivList.append([row1[0],row1[1]])
    cs1.reset()
    j = 1
    for lv1Riv in lv1RivList:
        expression2 = "flowId = %d"%(int(lv1Riv[1]))
        cs2 = arcpy.da.UpdateCursor(riv,['name','rivId','flowRiv','flowId','level'],where_clause=expression2)
        for row2 in cs2:
            print i + 1,j, expression2,row2[0],row2[1],'汇入',lv1Riv[0],lv1Riv[1]
            row2[4] = i + 1
            cs2.updateRow(row2)
            j += 1
        cs2.reset()
